<template>
  <div>
    <!-- <div style="position: relative;">
      <div class="lf">{{bili}}</div>
      <div class="rf">{{title}}</div>
    </div> -->
    <div class="select-wrap">
      <div class="select">
        <a-select v-model="wow_id" style="width: 160px" @change="handleChange">
          <a-select-option v-for="item in list" :key="item.wow_de_id" :value="item.wow_de_id">{{item.name}}</a-select-option>
        </a-select>
      </div>
    </div>


    <div id="myCharts"></div>
  </div>
</template>

<script>
import { TREND_CHART, GET_LIST_WOW } from "./server";
export default {
  props: ["list_id"],
  data() {
    return {
      title: "",
      bili: "",
      list: [],
      wow_id: ''
    };
  },
  mounted() {
    this.getListWow()
    // TREND_CHART({ 
    //   list_id: this.$route.params.list,
    //   wow_id: this.list_id
    // }).then(res => {
    //   if (!res) return;
    //   let data = [];
    //   let date = [];
    //   // this.title = res.data.title;
    //   // this.bili = res.data.arr;
    //   data = res.data.arr
    //   date = res.data.time
    //   // res.data.list.forEach(ele => {
    //   //   data.push(ele.test);
    //   //   date.push(ele.date_time);
    //   // });
    //   console.log(data, date)
    //   this.echartsInit(data, date);
    // });
  },
  methods: {
    getListWow() {
      GET_LIST_WOW({
        list_id: this.list_id
      }).then(res => {
        console.log(res, 59)
        this.list = res.data
        this.wow_id = res.data[0].wow_de_id
        // console.log(res, 59)
        // this.yxbId = res.data[0].wow_de_id
        this.getTrendChart()
      })
    },
    getTrendChart() {
      console.log(70)
      TREND_CHART({ 
        list_id: this.list_id,
        wow_id: this.wow_id
      }).then(res => {
        if (!res) return;
        let data = [];
        let date = [];
        // this.title = res.data.title;
        // this.bili = res.data.arr;
        data = res.data.arr
        date = res.data.time
        // res.data.list.forEach(ele => {
        //   data.push(ele.test);
        //   date.push(ele.date_time);
        // });
        this.echartsInit(data, date);
      });
    },
    handleChange(value) {
      this.wow_id = value
      this.getTrendChart()
    },
    echartsInit(data, date) {
      // 找到容器

      this.$nextTick(() => {
        let myChart = this.$echarts.init(document.getElementById("myCharts"));
        // 开始渲染
        myChart.setOption({
          tooltip: {
            trigger: "axis",
            position: function(pt) {
              return [pt[0], "10%"];
            }
          },
          title: {
            left: "center",
            text: "游戏币比价图"
          },
          xAxis: {
            type: "category",
            boundaryGap: false,
            data: date
          },
          yAxis: {
            type: "value",
            boundaryGap: [0, "100%"]
          },
          dataZoom: [
            {
              type: "inside",
              start: 0,
              end: 100
            },
            {
              start: 0,
              end: 100,
              handleIcon:
                "M10.7,11.9v-1.3H9.3v1.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4v1.3h1.3v-1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7V23h6.6V24.4z M13.3,19.6H6.7v-1.4h6.6V19.6z",
              handleSize: "80%",
              handleStyle: {
                color: "#fff",
                shadowBlur: 3,
                shadowColor: "rgba(0, 0, 0, 0.6)",
                shadowOffsetX: 2,
                shadowOffsetY: 2
              }
            }
          ],
          series: [
            {
              name: "模拟数据",
              type: "line",
              smooth: true,
              symbol: "none",
              sampling: "average",
              itemStyle: {
                color: "rgb(255, 0, 0)"
              },
              data: data
            }
          ]
        });
      });
    },
  }
};
</script>
<style lang="less" scoped>
#myCharts {
  width: 100%;
  height: 300px;
  margin-top: 30px;
}
.lf {
  position: absolute;
  left: 60px;
  top: 24px;
}
.rf {
  position: absolute;
  right: 60px;
  top: 24px;
}
.select-wrap {
  display: flex;
  justify-content: flex-end;
  .select {
    padding: 30px 120px 10px 0;
  }
}
</style>
